import request from '@/utils/request.js'

//  加入购物车
//  @param {String} skuId - 商品SKUID
//  @param {Integer} count - 商品数量
export const insertCart = ({ skuId, count }) => {
  return request('/member/cart', 'post', { skuId, count })
}

//  获取登录后的购物车列表
export const findCartList = () => {
  return request('/member/cart', 'get')
}

// 头部购物车删除接口
export const deleteCart = ids => {
  return request('/member/cart', 'delete', { ids })
}

/**
 * 修改购物车商品的状态和数量
 * @param {String} goods.skuId - 商品sku
 * @param {Boolean} goods.selected - 选中状态
 * @param {Integer} goods.count - 商品数量
 * @returns Promise
 */
export const updateCart = goods => {
  return request('/member/cart/' + goods.skuId, 'put', goods)
}

/**
 * 全选反选
 * @param {Boolean} selected - 选中状态
 * @param {Array<string>} ids - 所有的商品skuId集合
 * @returns Promise
 */
export const checkAllCart = ({ selected, ids }) => {
  return request('/member/cart/selected', 'put', { selected, ids })
}
